/**
 * 确认
 * */
// ===================================================================== Lazy
const Confirm = window.$Lazy.file(()=>import('@antd/common/confirm-submit'))
// ===================================================================== 
const Index = function(label, api, option){
	const opt = {
		...option
	}
	let { click, submit, isKeys, clear, onOk, onMy, onRefresh, hide, ghost, idStr='uuid', refresh, msg, onComplete, width } = opt
	
	let _disabled
	
	if(isKeys){
		_disabled = { disabled: !window.$fn.hasArray(this.state.selectedKeys) }
	}
	
	return { label, hide, loading:this.state.pagingLoading || this.state.submitLoading , ..._disabled, ghost, onClick:()=>{
		click?.()
		let { param, query } = opt
		if(query){
			if(typeof query === 'function'){
				const rs = query(this.state.selectedKeys, this.state.selectedRows)
				if(rs){
					param = rs
				}else{
					return
				}
			}else{
				param = query
			}
		}else{
			if(typeof param === 'function'){
				const rs = param(this.state.selectedKeys, this.state.selectedRows)
				if(rs){
					param = rs
				}else{
					return
				}
			}else{
				param = { [idStr]: isKeys ? this.state.selectedKeys : param, ...submit }
			}
		}
		
		Confirm.then( f=> {
			f.call(this, api, { 
				title:label,
				param, 
				clear, 
				onOk,
				onMy,
				onRefresh,
				refresh,
				msg,
				onComplete,
				width
			})
		} )
	}, ...option }
}
export default Index